#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/bn.h>

int main()
{
        BN_CTX *r[3];
        BIGNUM *a;
        BIGNUM *b;
        BIGNUM *c;
        BIGNUM *d;
        BIGNUM *e;
        BIGNUM *f;
        BIGNUM *g;
        char s[512+1] = "20181325201813242018132320181322201813212018132020181319";
        char t[512+1] = "201813262018132720181328201813292018133020181331";
        char *x;
        char *y;
        char *z;
        char *w;
        char *p;

        r[0] = BN_CTX_new();
        r[1] = BN_CTX_new();
        r[2] = BN_CTX_new();

        //BN_CTX_init(r[0]);
        //BN_CTX_init(r[1]);
        //BN_CTX_init(r[2]);

        a = BN_new();
        b = BN_new();
        c = BN_new();
        d = BN_new();
        e = BN_new();
        f = BN_new();
        g = BN_new();

BN_hex2bn(&a, s);
        BN_hex2bn(&b, t);

        BN_add(c, a, b);   //加法
        BN_sub(d, a, b);   //减法
        BN_mul(e, a, b, r[0]);  //乘法
        BN_div(f, g, a, b, r[1]);  //除法

        x = BN_bn2hex(c);
        y = BN_bn2hex(d);
        z = BN_bn2hex(e);
        w = BN_bn2hex(f);  //商
        p = BN_bn2hex(g);  //余数

        puts(x);
        puts(y);
        puts(z);
        puts(w);
        puts(p);

        BN_free(a);
        BN_free(b);
        BN_free(c);
        BN_free(d);
        BN_free(e);
        BN_free(f);
        BN_free(g);

        BN_CTX_free(r[0]);
        BN_CTX_free(r[1]);
        BN_CTX_free(r[2]);

free(x);
        free(y);
        free(z);
        free(w);
        free(p);

        return 0;
}
                                                                                                                                                  